using System;
using System.Windows.Input;

namespace RStein.PosterousReader.Common
{
    public class DelegateCommand<T> : ICommand
    {
        Action<T> m_executeAction;
        Func<T, bool> m_canExecuteAction;
        
      
      public DelegateCommand(Action<T> executeAction, Func<T, bool> canExecuteAction)
        {
            m_executeAction = executeAction;
            m_canExecuteAction = canExecuteAction;
        }
        public DelegateCommand(Action<T> executeAction)
            : this(executeAction, obj => true)
        {
        }
        public bool CanExecute(object parameter)
        {
          return (m_canExecuteAction((T)parameter));
        }
        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
           m_executeAction((T)parameter);
        }

        public bool CanExecuteCommand
        {
          get
          {
            return CanExecute(null);
          }
        }
    }  

}